package com.apes.fn.fico.reimbursement.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.frame.model.DutyCenter;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * @author pyb
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = RepaymentInvoiceItem.CONST_TABLE_NAME)
public class RepaymentInvoiceItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_repayment_invoice_item";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "还款发票明细", padding = 8)
    @Comment("还款发票明细编码")
    private String id;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cost_center_id", referencedColumnName = "id")
    @Comment("报销部门")
    private DutyCenter dutyCenter;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fee_type_id", referencedColumnName = "id")
    @Comment("费用类型")
    private FeeType feeType;

    @ManyToOne(fetch = FetchType.LAZY)
    @Comment("发票类型")
    @JoinColumn(name = "invoice", referencedColumnName = "id")
    private Enumeration invoice;

    @Comment("发票号码")
    @Column(name = "invoice_number", length = 120)
    private String invoiceNumber;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("税率")
    private Tax tax;


    @Comment("价税合计金额")
    @Column(name = "price_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double priceTax = 0;

    @Comment("进项税金")
    @Column(name = "input_tax_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double inputTaxAmount = 0;

    @Comment("原因")
    @Column(name = "reason", length = 120)
    private String reason;

    @ManyToOne(optional = false)
    @JoinColumn(name = "debit_repayment_item_id", referencedColumnName = "id")
    @Comment("借支还款")
    private DebitRepaymentItem debitRepaymentItem;

}
